package com.example.wangzh.mytest;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;

import com.example.wangzh.mytest.base.BaseActivity;
import com.example.wangzh.mytest.databinding.ActivityLayoutTestBinding;

/**
 * Created by zhwang16 on 2018/9/21.
 */

public class LayoutTestActivity extends BaseActivity<ActivityLayoutTestBinding> {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mBinding.btnSpaceLager.setOnClickListener(this::onClick);
        mBinding.btnSpaceSmaller.setOnClickListener(this::onClick);
    }

    @SuppressLint("NonConstantResourceId")
        //最新版本gradle插件不建议使用这种case后面带id的写法
    void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_space_lager:
                mBinding.layoutTestView.setColumnSpacing(mBinding.layoutTestView.getColumnSpacing() + 20);
                mBinding.layoutTestView.setRowSpacing(mBinding.layoutTestView.getRowSpacing() + 20);
                break;
            case R.id.btn_space_smaller:
                int columnSpacing = mBinding.layoutTestView.getColumnSpacing() - 20;
                int rowSpacing = mBinding.layoutTestView.getRowSpacing() - 20;
                if (columnSpacing < 0) {
                    columnSpacing = 0;
                }
                if (rowSpacing < 0) {
                    rowSpacing = 0;
                }
                mBinding.layoutTestView.setColumnSpacing(columnSpacing);
                mBinding.layoutTestView.setRowSpacing(rowSpacing);
                break;
            default:
                break;
        }
    }


}
